package com.hilyb;

import com.hilyb.entities.Book;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;

/**
 * Hello world!
 */
public class App {
    public static void main(String[] args) {
        Configuration configuration = new Configuration();
        configuration.configure("hibernate.cfg.xml");
        StandardServiceRegistryBuilder standardServiceRegistryBuilder =
                new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());
        StandardServiceRegistry standardServiceRegistry = standardServiceRegistryBuilder.build();
        SessionFactory sessionFactory = configuration.buildSessionFactory(standardServiceRegistry);

        Book book = new Book();
        book.setTitle("流量分成");
        book.setAuthor("laiyubin");
        book.setDescription("每篇合格原创经验在百度经验发布后1年内，每天的有效流量将按照一定比例折算成现金，计入您的账户；不同等级的回享作者，分成比例不同");
        Session session = sessionFactory.openSession();
        Transaction tx=session.beginTransaction();
        session.save(book);
        tx.commit();
        session.close();
        sessionFactory.close();

    }
}
